home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 7697 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  997 b 

  1. Path: pegasus.odyssee.net!news
  2. From: imaze@odyssee.net (Marc Mazerolle)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: what happens w/delete called twice ?
  5. Date: Sun, 25 Feb 1996 05:17:27 GMT
  6. Organization: Odyssee Internet
  7. Message-ID: <4goqk0$jul@pegasus.odyssee.net>
  8. References: <kcc.423.0EE12CF6@interaccess.com>
  9. Reply-To: imaze@odyssee.net
  10. NNTP-Posting-Host: pool21_10.odyssee.net
  11. X-Newsreader: Forte Free Agent v0.55
  12.  
  13. kcc@interaccess.com (kcc) wrote:
  14.  
  15. >Hello,
  16.  
  17. >    Can someone tell me... what happens when delete is called twice for the same 
  18. >memory deallocation ie.,
  19.  
  20. >    SOME_STRUCT    *struct_p    = new SOME STRUCT;
  21.  
  22. >    if ( foo_a() )
  23. >    {
  24. >        delete struct_p;
  25. >        retvalue = 0;
  26. >    }
  27. >    else
  28. >    {
  29. >        retvalue = foo_b();
  30. >    }
  31.  
  32. >    delete struct_p;
  33.  
  34. >    return( retvalue );
  35.  
  36.  
  37.  
  38. >Thanx !
  39. >kcc
  40.  
  41. Most compilers won't produce any error since their delete function
  42. will nullify your pointer and deleting a null pointer is also
  43. supported by most compiler.
  44.  
  45. But, if you wan't to write portable code, i suggest you don't do it.
  46.  
  47.